<template>
  <div id="lesson" class="lesson">
	  <div id="lessonSubtitle" class="lessonSubtitle">
		  <tab>
			  <tab-item :selected="page === 'myLesson'" @on-item-click="getMyActivity">即将开课</tab-item>
			  <tab-item :selected="page === 'getPendingConfirm'" @on-item-click="getPendingConfirm" :badge-label="this.$store.state.user.pendingActNum + ''">待确认</tab-item>
			  <tab-item :selected="page === 'getPendingFeedback'" @on-item-click="getPendingFeedback">待反馈</tab-item>
			  <tab-item :selected="page === 'getCompleted'" @on-item-click="getCompleted">已完成</tab-item>
		  </tab>
	  </div>

	  <div v-if="page == 'myLesson'">
		  <lessonList curURL="user_activity/pages/getInComingActivityModel" role="teacher" status="0" jumpToObjectDetails="lessonDetails" type="S_LOV_LESSON" seq="asc"></lessonList>
	  </div>
	  <div v-else-if="page == 'getPendingConfirm'">
		  <lessonList curURL="user_activity/pages/getActivityModelByStatus" role="teacher" status="0" jumpToObjectDetails="lessonDetails" type="S_LOV_LESSON" seq="asc"></lessonList>
	  </div>
	  <div v-else-if="page == 'getPendingFeedback'">
		  <lessonList curURL="user_activity/pages/getActivityModelByStatus" role="teacher" status="1" jumpToObjectDetails="lessonDetails" type="S_LOV_LESSON" seq="asc"></lessonList>
	  </div>
	  <div v-else-if="page == 'getCompleted'">
		  <lessonList curURL="user_activity/pages/getActivityModelByStatus" role="teacher" status="2" jumpToObjectDetails="lessonDetails" type="S_LOV_LESSON" seq="desc"></lessonList>
	  </div>

  </div>
</template>

<script>
	import bus from '@/event/eventBus'
	import lessonList from '../../../../components/mobile/scroller/scrollerActivity'
	import NetWorking from '../../../../utils/networking'
	import {Tab, TabItem, Badge} from 'vux'
	export default {
		name: "lesson",
		components: {
			lessonList,
			Tab,
			TabItem,
			Badge
		},
		data() {
			return {
				page: 'myLesson'
			}
		},
		beforeRouteLeave(to, from, next){

			//存储当前页面信息
			this.$store.commit('CREATE_URL_PARAMS', {name: from.name, params: this.page})
			next()
		},
		mounted: function () {
			bus.$emit("barController", 0)
			bus.$emit("setTopSimpleTitle", '活动详情')
			bus.$emit("userDefinedEvent", 3)
		},
		created: function () {
			this.$store.commit('FETCH_URL_PARAMS')
			if(this.$route.query.page == null){
				if(this.$store.state.user.urlParamsMap != null && this.$store.state.user.urlParamsMap["lesson"] != null){
					this.page = this.$store.state.user.urlParamsMap["lesson"].params
				}
			}else{
				this.page = this.$route.query.page
			}
		},
		watch: {
			page: function () {
				NetWorking.doGet(
					'notification/getPendingActivityNum',
					null,
					{
						params: {
							type: 'S_LOV_LESSON',
							rolePlay: 'teacher'
						}
					}
				).then(
					response => {
						let rs = response.data
						if(rs.error_code == 0){
							this.$store.dispatch('createPendingActNum', rs.pending_act_num)
						}else{
							alert(rs.error_message)
						}
					}
				)
			}
		},
		methods: {
			getMyActivity() {
				this.page = 'myLesson'
			},
			getPendingConfirm() {
				this.page = 'getPendingConfirm'
			},
			getCompleted() {
				this.page = 'getCompleted'
			},
			getPendingFeedback() {
				this.page = 'getPendingFeedback'
			}
		}
	}
</script>

<style>
	.lessonSubtitle {
		margin-top: 46px;
		position: relative;
		z-index: 99;
	}

	.badge-value {
		display: inline-block!important;
	}

	.pendingBadge {
		margin-bottom: 10px;
		margin-left: 2px;
	}
</style>
